package com.lucian.requestForWord;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

/**
 * 请求转发
 */
public class RequestForWrod extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //获取指定请求参数中的值
        String name = req.getParameter("name");
        //打散
//        byte[] bytes = name.getBytes("ISO8859-1");
        //组装
//        String s = new String(bytes, "UTF-8");
        //输出请求参数中的值
//        System.out.println("this is normal" + name);
//        System.out.println(s);

        //向域属性中放入数据
        req.setAttribute("attrname", name);
//        req.setAttribute("attrage",age);

        //编码  :打散成字节
        name = URLEncoder.encode(name, "UTF-8");

        resp.sendRedirect("other?pname=" + name + "&page=23");

//        req.getRequestDispatcher("other").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
